<?php
require $_SERVER['DOCUMENT_ROOT'].'/../_core/common.php';

$msg = array();

//权限验证
if( Role::init() == false ){
	$msg['error'] = false;
	$msg['string'] = '权限不足！';
	$myjson = json_encode($msg); 
	echo $myjson; 
	exit;
}

$db = new DB('star');

$id = isset($_POST['id']) ? intval($_POST['id']) : '';

$star_sql = 'select title_id,title,html from star where title_id='.$id;
$star_rs = $db->query($star_sql)->getOne();

if( $star_rs['title_id'] < 1 ){//id不存在
	$msg['error'] = false;
	$msg['string'] = '参数有误！';
}else{
	//更新is_del字段
	$data=array('is_del'=>1,'updated'=>time(),'edit_uid'=>Sessions::get('uid'));
	$db->table('star')->where('title_id='.$star_rs['title_id'])->update($data)->run();
	
	$filename = '/v/'.$star_rs['title_id'].'/index.html';
	@file_put_contents( $_SERVER['DOCUMENT_ROOT'].$filename, h_d($star_rs['html']) );
	
	$msg['error'] = true;
	$msg['string'] = '成功恢复《'.$star_rs['title'].'》!';
}
$myjson = json_encode($msg); 
echo $myjson; 
exit;